package tests.suite.tests.xspf4x
{
	import com.gdcnano.libs.xspf4x.XSPF4X;
	import com.gdcnano.libs.xspf4x.XSPFTrack;
	import com.gdcnano.nanoamp.media.sound.playlist.XSPFiTrack;
	
	import flexunit.framework.Assert;

	public class XSPFTrackTest
	{
		
		private static const ALBUM:String = "Frank Sinatra's Greatest Hits";
		
		private static const ANNOTATION:String = "This is my theme song.";
		
		private static const CREATOR:String = "Frank Sinatra";
		
		private static const DURATION:uint = 19200;
		
		private static const IDENTIFIER:String = "magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C";
		
		private static const IMAGE:String = "http://franksinatra.com/img/myway";
		
		private static const INFO:String = "http://franksinatra.com/myway";
		
		private static const LOCATION:String = "http://example.com/my.mp3";
		
		private static const TITLE:String = "My Way";
		
		private static const TRACKNUM:uint = 3;
		
		
		private static const XMLTrack:XML =
			<playlist version="1" xmlns="http://xspf.org/ns/0/">
				<title>Sample playlist</title>
				<trackList><track>
				  <location>http://example.com/my.mp3</location>
				  <identifier>magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C</identifier>
				  <title>My Way</title>
				  <creator>Frank Sinatra</creator>
				  <annotation>This is my theme song.</annotation>
				  <info>http://franksinatra.com/myway</info>
				  <image>http://franksinatra.com/img/myway</image>
				  <album>Frank Sinatra's Greatest Hits</album>
				  <trackNum>3</trackNum>
				  <duration>19200</duration>
				  <link rel="http://foaf.org/namespace/version1">http://socialnetwork.org/foaf/mary.rdfs</link>
				  <meta rel="http://example.org/key">value</meta>
				  <extension application="http://example.com">
					<clip start="25000" end="34500"/>
				  </extension>
				</track></trackList>
			</playlist>;
		
		private var _xspfTrack:XSPFTrack;
		
		public function XSPFTrackTest()
		{
		}
		
		[Test]
		public function canParseXSPFTrackInfo():void
		{
			var xmlTrack:XML = XMLTrack._xspfns::trackList._xspfns::track[0];
			
			_xspfTrack = new XSPFTrack(xmlTrack);
			
			Assert.assertEquals(ALBUM, _xspfTrack.album);
			
			Assert.assertEquals(ANNOTATION, _xspfTrack.annotation);
			
			Assert.assertEquals(CREATOR, _xspfTrack.creator);
			
			Assert.assertEquals(DURATION, _xspfTrack.duration);
			
			Assert.assertEquals(IDENTIFIER, _xspfTrack.identifier);
			
			Assert.assertEquals(IMAGE, _xspfTrack.image);
			
			Assert.assertEquals(INFO, _xspfTrack.info);
			
			Assert.assertEquals(LOCATION, _xspfTrack.location);
			
			Assert.assertEquals(TITLE, _xspfTrack.title);
			
			Assert.assertEquals(TRACKNUM, _xspfTrack.trackNum);
			
		}
		
		[Test]
		public function canConvertIntoITrack():void
		{
			var xmlTrack:XML = XMLTrack._xspfns::trackList._xspfns::track[0];
			
			_xspfTrack = new XSPFTrack(xmlTrack);
			
			var xspfITrack:XSPFiTrack = new XSPFiTrack(_xspfTrack);
			
			Assert.assertEquals(ALBUM, xspfITrack.album);
			
			Assert.assertEquals(CREATOR, xspfITrack.artist);
			
			Assert.assertEquals(TITLE, xspfITrack.name);
			
			Assert.assertEquals(LOCATION, xspfITrack.location);
		}
		
		private function get _xspfns():Namespace
		{
			return XSPF4X.xspfNamespace;
		}
	}
}